// components/owner/owner-base-info/index.js
import { PACKAGE_OWNER_PAGE, COMMON_PAGE } from '../../../constants/route';
import { getPicFullPath } from '../../../common/utils';
import { navTo, canIUse } from '../../../common/env';

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        name: {
            type: String,
            value: '匿名',
        },
        userId: String,
        phone: String,
        avatar: String,
    },
    observers: {
        'avatar': function (pic) {
            this.setData({ avatarUrl: getPicFullPath(pic) });
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        avatarUrl: '',
        showBindMobilePopup: false,
        canIUseGetUserProfile: canIUse('getUserProfile'),
    },

    /**
     * 组件的方法列表
     */
    methods: {
        // 跳转到个人主页
        gotoUserPage: function() {
            const { userId } = this.data;
            navTo(COMMON_PAGE.shareUser, {
                userId,
                owner: true,
            });
        },
        // 获取用户信息
        getUserInfo(e) {
            this.triggerEvent('getUserInfo', e.detail);
        },
        // 展示绑定手机
        showBindMobile() {
            if (this.data.phone) return;
            this.setData({
                showBindMobilePopup: true,
            });
        },
        // 绑定手机成功
        bindMobileSuccess(e) {
            const { mobile } = e.detail;
            this.triggerEvent('bindMobileSuccess', mobile);
        },
    }
})
